#include "GlobalData.h"

using namespace std;
const char* monsterImagePath_1[15] =
{ "node/hitMonster/aphid/",
"node/hitMonster/bat/",
"node/hitMonster/cockroach/",
"node/hitMonster/fly/",
"node/hitMonster/hamster/",
"node/hitMonster/ladybug/",
"node/hitMonster/longicorn/",
"node/hitMonster/mosquito/",
"node/hitMonster/moth/",
"node/hitMonster/scorpion/",
"node/hitMonster/spider/",
"node/hitMonster/termite/",
"node/hitMonster/uang/",
"node/hitMonster/wriggler/",
"node/hitMonster/budworm/" };
const char* monsterImagePath_2_1[9] =
{
	"20170515-level1-1.png",
	"20170515-level1-2.png",
	"20170515-level1-3.png",
	"20170515-level1-4.png",
	"20170815-level2.png",
	"20170815-level3.png",
	"20170815-level4.png",
	"20170815-level5.png",
	"20170815-level6.png"
};
const char* monsterImagePath_2_2[21] =
{
	"20170515-level1-1.png",
	"20170515-level1-2.png",
	"20170515-level1-3.png",
	"20170515-level1-4.png",
	"20170815-level2-1.png",
	"20170815-level2-2.png",
	"20170815-level2-3.png",
	"20170815-level2-4.png",
	"20170815-level3-1.png",
	"20170815-level3-2.png",
	"20170815-level3-3.png",
	"20170815-level3-4.png",
	"20170815-level4-1.png",
	"20170815-level4-2.png",
	"20170815-level4-3.png",
	"20170815-level4-4.png",
	"20170815-level5-1.png",
	"20170815-level5-2.png",
	"20170815-level5-3.png",
	"20170815-level5-4.png",
	"20170815-level6.png"
};
const char* weaponImagePath_1[9] =
{
	"node/hitMonster/cannon/",
	"node/hitMonster/mortar/",
	"node/hitMonster/crossbow/",
	"node/hitMonster/doublebows/",
	"node/hitMonster/liannu/",
	"node/hitMonster/longbow/",
	"node/hitMonster/trebuchet/",
	"node/hitMonster/tripleBallista/",
	"node/hitMonster/woodSlingshot/"
};
const char* weaponImagePath_2_1[3] =
{
	"20170817-8-cannon-1.png",
	"20170817-8-cannon-2.png",
	"20170817-8-cannon-3.png"
};
const char* weaponImagePath_2_2[3] =
{
	"20170817-9-Mortar-1.png",
	"20170817-9-Mortar-2.png",
	"20170817-9-Mortar-3.png"
};
const char* weaponImagePath_2_3[8] =
{
	"20170816-3crossbow-1.png",
	"20170816-3crossbow-2.png",
	"20170816-3crossbow-3.png",
	"20170816-3crossbow-4.png",
	"20170816-3crossbow-5.png",
	"20170816-3crossbow-6.png",
	"20170816-3crossbow-7.png",
	"20170816-3crossbow-8.png"
};
const char* weaponImagePath_2_4[8] =
{
	"20170817-Double-crossbows-1.png",
	"20170817-Double-crossbows-2.png",
	"20170817-Double-crossbows-3.png",
	"20170817-Double-crossbows-4.png",
	"20170817-Double-crossbows-5.png",
	"20170817-Double-crossbows-6.png",
	"20170817-Double-crossbows-7.png",
	"20170817-Double-crossbows-8.png"
};
const char* weaponImagePath_2_5[8] =
{
	"20170816-Liannu-1.png",
	"20170816-Liannu-2.png",
	"20170816-Liannu-3.png",
	"20170816-Liannu-4.png",
	"20170816-Liannu-5.png",
	"20170816-Liannu-6.png",
	"20170816-Liannu-7.png",
	"20170816-Liannu-8.png"
};
const char* weaponImagePath_2_6[8] =
{
	"20170613-Longbow-1.png",
	"20170613-Longbow-2.png",
	"20170613-Longbow-3.png",
	"20170613-Longbow-4.png",
	"20170613-Longbow-5.png",
	"20170613-Longbow-6.png",
	"20170613-Longbow-7.png",
	"20170613-Longbow-8.png"
};

const char* weaponImagePath_2_7[8] =
{
	"20170817-7-Trebuchet-0.png",
	"20170817-7-Trebuchet-1.png",
	"20170817-7-Trebuchet-2.png",
	"20170817-7-Trebuchet-3.png",
	"20170817-7-Trebuchet-4.png",
	"20170817-7-Trebuchet-5.png",
	"20170817-7-Trebuchet-6.png",
	"20170817-7-Trebuchet-7.png"
};
const char* weaponImagePath_2_8[8] =
{
	"20170817-6-Triple-Ballista-1.png",
	"20170817-6-Triple-Ballista-2.png",
	"20170817-6-Triple-Ballista-3.png",
	"20170817-6-Triple-Ballista-4.png",
	"20170817-6-Triple-Ballista-5.png",
	"20170817-6-Triple-Ballista-6.png",
	"20170817-6-Triple-Ballista-7.png",
	"20170817-6-Triple-Ballista-8.png"
};
const char* weaponImagePath_2_9[8] =
{
	"20170612-1.png",
	"20170612-2.png",
	"20170612-3.png",
	"20170612-4.png",
	"20170612-5.png",
	"20170612-6.png",
	"20170612-7.png",
	"20170612-8.png"
};

void GlobalData::loadBaseData()
{
	setIdentity(Tools::getIdentityContent().c_str());
}

void GlobalData::loadMuashroomImages()
{
	Director::getInstance()->getTextureCache()->addImageAsync("node/hitMonster/woodSlingshot/20170612-stone.png", CC_CALLBACK_1(GlobalData::loadingCallBack, this));
	Director::getInstance()->getTextureCache()->addImageAsync("node/hitMonster/20170613-Longbow.png", CC_CALLBACK_1(GlobalData::loadingCallBack, this));
	Director::getInstance()->getTextureCache()->addImageAsync("node/hitMonster/20170817-bom.png", CC_CALLBACK_1(GlobalData::loadingCallBack, this));
	for (int i = 0; i < 15; i++)
	{
		if (i >= 13)
		{
			for (int j = 0; j < 21; j++)
			{
				string str1 = monsterImagePath_1[i];
				string str2 = monsterImagePath_2_2[j];
				string str = str1 + str2;
				Director::getInstance()->getTextureCache()->addImageAsync(str, CC_CALLBACK_1(GlobalData::loadingCallBack, this));
			}
		}
		else
		{
			for (int j = 0; j < 9; j++)
			{
				string str1 = monsterImagePath_1[i];
				string str2 = monsterImagePath_2_1[j];
				string str = str1 + str2;
				Director::getInstance()->getTextureCache()->addImageAsync(str, CC_CALLBACK_1(GlobalData::loadingCallBack, this));
			}
		}
	}
	for (int i = 0; i < 9; i++)
	{
		string str1 = weaponImagePath_1[i];
		switch (i)
		{
		case 0:
		{
			for (int j = 0; j < 3; j++)
			{
				string str2 = weaponImagePath_2_1[j];
				string str = str1 + str2;
				Director::getInstance()->getTextureCache()->addImageAsync(str, CC_CALLBACK_1(GlobalData::loadingCallBack, this));
			}
			break;
		}
		case 1:
		{
			for (int j = 0; j < 3; j++)
			{
				string str2 = weaponImagePath_2_2[j];
				string str = str1 + str2;
				Director::getInstance()->getTextureCache()->addImageAsync(str, CC_CALLBACK_1(GlobalData::loadingCallBack, this));
			}
			break;
		}
		case 2:
		{
			for (int j = 0; j < 8; j++)
			{
				string str2 = weaponImagePath_2_3[j];
				string str = str1 + str2;
				Director::getInstance()->getTextureCache()->addImageAsync(str, CC_CALLBACK_1(GlobalData::loadingCallBack, this));
			}
			break;
		}
		case 3:
		{
			for (int j = 0; j < 8; j++)
			{
				string str2 = weaponImagePath_2_4[j];
				string str = str1 + str2;
				Director::getInstance()->getTextureCache()->addImageAsync(str, CC_CALLBACK_1(GlobalData::loadingCallBack, this));
			}
			break;
		}
		case 4:
		{
			for (int j = 0; j < 8; j++)
			{
				string str2 = weaponImagePath_2_5[j];
				string str = str1 + str2;
				Director::getInstance()->getTextureCache()->addImageAsync(str, CC_CALLBACK_1(GlobalData::loadingCallBack, this));
			}
			break;
		}
		case 5:
		{
			for (int j = 0; j < 8; j++)
			{
				string str2 = weaponImagePath_2_6[j];
				string str = str1 + str2;
				Director::getInstance()->getTextureCache()->addImageAsync(str, CC_CALLBACK_1(GlobalData::loadingCallBack, this));
			}
			break;
		}
		case 6:
		{
			for (int j = 0; j < 8; j++)
			{
				string str2 = weaponImagePath_2_7[j];
				string str = str1 + str2;
				Director::getInstance()->getTextureCache()->addImageAsync(str, CC_CALLBACK_1(GlobalData::loadingCallBack, this));
			}
			break;
		}
		case 7:
		{
			for (int j = 0; j < 8; j++)
			{
				string str2 = weaponImagePath_2_8[j];
				string str = str1 + str2;
				Director::getInstance()->getTextureCache()->addImageAsync(str, CC_CALLBACK_1(GlobalData::loadingCallBack, this));
			}
			break;
		}
		case 8:
		{
			for (int j = 0; j < 8; j++)
			{
				string str2 = weaponImagePath_2_9[j];
				string str = str1 + str2;
				Director::getInstance()->getTextureCache()->addImageAsync(str, CC_CALLBACK_1(GlobalData::loadingCallBack, this));
			}
			break;
		}
		}
	}
}

void GlobalData::loadPaoPaoImages()
{
	Director::getInstance()->getTextureCache()->addImageAsync("20170828-Parkourbootbg.jpg", CC_CALLBACK_1(GlobalData::loadingCallBack, this));
	Director::getInstance()->getTextureCache()->addImageAsync("20170828-Parkourboottop.png", CC_CALLBACK_1(GlobalData::loadingCallBack, this));
}
void GlobalData::loadingCallBack(cocos2d::Texture2D *texture)
{
	CCLOG("sb");
}
static GlobalData *s_SharedInstance = nullptr;

GlobalData* GlobalData::getInstance()
{
	if (!s_SharedInstance)
	{
		s_SharedInstance = new (std::nothrow) GlobalData();
		CCASSERT(s_SharedInstance, "FATAL: Not enough memory");
		s_SharedInstance->init();
	}

	return s_SharedInstance;
}

void GlobalData::init()
{
	m_parkId = "";
	m_terminalId = "";
	m_macId = "";

	CCDictionary* setting = CCDictionary::createWithContentsOfFile("data/setting.xml");
	if (setting) 
	{
		m_icometUrl = setting->valueForKey("icomet")->getCString();
		m_serverApiStartUrl = setting->valueForKey("server_api_start")->getCString();
		m_serverApiSoltUrl = setting->valueForKey("server_api_slot")->getCString();
		m_soundPath = setting->valueForKey("sound_path")->getCString();
		m_getServerApiMineUrl = setting->valueForKey("server_api_gold_mine")->getCString();
		m_getServerApiSellUrl = setting->valueForKey("server_api_gold_sell")->getCString();
		m_getServerApiHideUrl = setting->valueForKey("server_api_gold_hide")->getCString();
		m_identityPath = setting->valueForKey("identity_path")->getCString();
		m_webSocketUrl = setting->valueForKey("web_socket_url")->getCString();
	}
	else 
	{
		MessageBox("can not find setting.xml", "Warn");
	}

	auto resourceDic = FileUtils::getInstance()->getValueMapFromFile("data/resource.xml");
	m_noMushroomAlert = resourceDic.at("noMushroomAlert").asString();
	ValueVector gradeArr = resourceDic.at("grade").asValueVector();
	int i = 0;
	for (auto&iterm : gradeArr)
	{
		string gradeStr = iterm.asString();
		m_gradeArr[i] = gradeStr;
		i++;
	}

	loadBaseData();
}



void GlobalData::setParkId(const char* parkId)
{
	m_parkId = string(parkId);
}

string GlobalData::getParkId()
{
	return m_parkId;
}

void GlobalData::setTerminalId(const char* terminalId)
{
	m_terminalId = string(terminalId);
}

string GlobalData::getTerminalId()
{
	return m_terminalId;
}

void GlobalData::setMacId(const char* macId)
{
	m_macId = string(macId);
}

string GlobalData::getMacId()
{
	return m_macId;
}

string GlobalData::getICometUrl()
{
	return m_icometUrl;
}

void GlobalData::setICometSeq(int seq)
{
	m_icometSeq = seq;
}
int GlobalData::getICometSeq()
{
	return m_icometSeq;
}

string GlobalData::getServerApiStartUrl()
{
	return m_serverApiStartUrl;
}

string GlobalData::getServerApiSoltUrl()
{
	return m_serverApiSoltUrl;
}

string GlobalData::getServerApiMineUrl()
{
	return m_getServerApiMineUrl;
}

string GlobalData::getServerApiSellUrl()
{
	return m_getServerApiSellUrl;
}

string GlobalData::getServerApiHideUrl()
{
	return m_getServerApiHideUrl;
}

string GlobalData::getSoundPath()
{
	return m_soundPath;
}

string GlobalData::getIdentityPath()
{
	return m_identityPath;
}

void GlobalData::setIdentity(const char* identity)
{
	m_identity = identity;
}
string GlobalData::getIdentity()
{
	return m_identity;
}

string GlobalData::getWebSocketUrl()
{
	return m_webSocketUrl;
}

void GlobalData::setComRevice(const char* data)
{
	m_comRevice = data;
}

string GlobalData::getComRevice()
{
	return m_comRevice;
}